let udpProxy = require("./udpproxy.js").udpProxy;
let createtcpProxy = require("./tcpproxy.js").createtcpProxy;

let ev = require("./getConfig").ev;//.path;
let config1 = require(ev.path);
if (!config1.list) {
    console.log("配置错误");
    process.exit(0);
}
let serverList = config1.list;
let index = ev.index === undefined ? 0 : ev.index;
function createServerBy(sid) {
    try {
        if (sid == undefined) {
            return;
        }
        let index = ~~(sid / 2);
        let turnServer = sid % 2 ? createtcpProxy : udpProxy;
        // console.log(`Worker ${process.pid} started`);
        let serverconfig = serverList[index];
        if (!serverconfig)
            return console.log(">process exit?");
        turnServer(serverconfig.listenport, serverconfig.listenIp, serverconfig.turnport, serverconfig.tcpturnIp)
    }
    catch (e) {

    }
}
createServerBy(index);
//evstr=JSON.stringify({path:"./config.js",index:1})// {"path":"./config.js","index":1}
// 启动命令 node ./childprocess  {\"path\":\"./config.js\",\"index\":2}

process.on('uncaughtException', function () {

});